<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : shop.class.php   FILE_PATH : \\classes\application\shoptag.class.php
 * 商铺标签操作类
 *
 * @copyright workflow_system 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Thu Jul 2 11:11:42 CST 2009
 */

defined('Base_Use_Sign') or die("this is invalid system!please contact <a href='http://www.shopnc.net'>www.shopnc.net</>.");

class ShopTag extends FrameWork {
	/**
	 * 获得标签列表
	 *
	 * @param array $condition
	 * @param object $obj_page
	 * @return array/boolean
	 */
	function getTagList ($condition,$obj_page) {
		if (intval($condition['shop_id']) > 0) {
			$conditionstr = $this->_conditionSearch($condition);
			$tag_array   = $GLOBALS['db']->GetList($conditionstr, &$obj_page, "shop_tag");
			return $tag_array;			
		} else {
			return false;
		}
	}
	/**
	 * 构造检索条件
	 *
	 * @param array $condition
	 * @return string
	 */
	function _conditionSearch ($condition) {
		$condition_str = "";
		//按店铺
		if ($condition['shop_id'] != '') {
			$condition_str .= " where shop_id = '" . $condition['shop_id'] . "'";
		}
		//显示状态
		if ($condition['tag_display'] == 'block') {
			$condition_str .= " and tag_display = 0";
		}
		//排序
		if ($condition['order_by'] != '') {
			$condition_str .= " order by ".$condition['order_by'];
		}
		return $condition_str;
	}
	/**
	 * 添加标签
	 *
	 * @param array $input
	 * @return boolean
	 */
	function addTag($input) {
		if (is_array($input)) {
			$valueArray = array();
			$valueArray['shop_id'] = $input['shop_id'];	//店铺id
			$valueArray['tag_name'] = $input['txtTagname']; //标签名称
			if ($input['txtTagurl'] != '') {
				$valueArray['tag_url'] = $input['txtTagurl'];	//链接地址	
			}
			if ($input['txtTagcontent'] != '') {
				$valueArray['tag_content'] = $input['txtTagcontent'];	//标签内容	
			}
			$valueArray['tag_display'] = $input['txtTagdisplay'];	//显示状态
			$valueArray['tag_sort'] = $input['txtTagsort'];	//排序
			$valueArray['tag_time'] = time();	//时间
			return $GLOBALS['db']->InsertRow($valueArray, "shop_tag", "tag_id");			
		} else {
			return false;
		}
	}
	/**
	 * 统计某店铺的标签数量
	 *
	 * @param int $shop_id
	 * @return array
	 */
	function countTagNumber ($shop_id) {
		if (intval($shop_id) > 0) {
			return $GLOBALS['db']->CountRows("shop_tag", "shop_id = '" . $shop_id . "'");
		} else {
			return false;
		}
	}
	/**
	 * 获取一条标签信息
	 *
	 * @param int $id
	 * @param string $fields
	 * @return array/boolean
	 */
	function getOneTag($id,$fields="*") {
		if (intval($id) > 0) {
			return $GLOBALS['db']->GetOneRow($id,"shop_tag","tag_id",$fields);
		} else {
			return false;
		}
	}
	/**
	 * 编辑标签
	 *
	 * @param array $input
	 * @return boolean
	 */
	function updateTag ($input) {
		if (is_array($input) && intval($input['tag_id']) > 0) {
			$valueArray = array();
			$valueArray['tag_name'] = $input['txtTagname']; //标签名称
			$valueArray['tag_url'] = $input['txtTagurl'];	//链接地址	
			$valueArray['tag_content'] = $input['txtTagcontent'];	//标签内容	
			$valueArray['tag_display'] = $input['txtTagdisplay'];	//显示状态
			$valueArray['tag_sort'] = $input['txtTagsort'];	//排序			
			return $GLOBALS['db']->UpdateRows("shop_tag", $valueArray, "tag_id = '" . $input['tag_id'] . "' and shop_id = '" . $input['shop_id'] . "'",$genre = "common");
		} else {
			return false;
		}
	}
	/**
	 * 删除标签
	 *
	 * @param int $id
	 * @param int $shop_id
	 * @return boolean
	 */
	function deleteTag ($id,$shop_id){
		if (intval($id) > 0) {
			return $GLOBALS['db']->DeleOneRow($id,"shop_tag","tag_id","and shop_id = '" . $shop_id . "'");
		} else {
			return false;
		}
	}
}
?>